<template>
  <view class="page-container">
    <!-- 顶部导航栏 -->
    <uni-nav-bar
      :border="false"
      title="抵用券激活"
      fixed
      left-icon="back"
      @clickLeft="goBack"
    />

    <view class="content">
      <!-- 可激活抵用券卡片 -->
      <view class="activate-card">
        <view class="card-icon">
          <uni-icons type="wallet" size="40" color="#ff9500"></uni-icons>
        </view>
        <view class="card-content">
          <text class="card-label">可激活抵用券：</text>
          <text class="card-amount">{{ activatableAmount }}</text>
        </view>
      </view>

      <!-- 激活表单 -->
      <view class="activate-form">
        <view class="form-title">激活抵用券</view>

        <view class="form-item">
          <text class="form-label">请输入激活抵用券数</text>
          <view class="input-wrapper">
            <uni-easyinput
              v-model="activateCount"
              type="number"
              placeholder="请输入激活抵用券数"
              :clearable="true"
            />
            <view class="all-btn" @click="activateAll">全部激活</view>
          </view>
        </view>

        <view class="form-item">
          <text class="form-label">激活至抵用券余额</text>
          <view class="balance-info">
            <text class="balance-label">当前余额：</text>
            <text class="balance-amount">{{ currentBalance }}</text>
          </view>
        </view>

        <view class="submit-btn" @click="confirmActivate">确认激活</view>
      </view>

      <!-- 激活记录 -->
      <view class="record-section">
        <view class="record-header">
          <text class="record-title">激活记录</text>
        </view>

        <view class="record-list">
          <view
            v-for="(item, index) in activateRecords"
            :key="index"
            class="record-item"
          >
            <view class="record-left">
              <text class="record-time">{{ item.time }}</text>
            </view>
            <view class="record-right">
              <text class="record-amount">{{ item.amount }}</text>
            </view>
          </view>

          <!-- 空状态 -->
          <view v-if="activateRecords.length === 0" class="empty-state">
            <image
              src="/static/logo.png"
              class="empty-image"
              mode="aspectFit"
            ></image>
            <text class="empty-text">暂无数据~</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";

// 可激活抵用券金额
const activatableAmount = ref("4.7800");

// 当前余额
const currentBalance = ref("1402.82");

// 激活数量
const activateCount = ref("");

// 激活记录
const activateRecords = ref([
  {
    time: "2025-10-02 10:55:39",
    amount: "4.88",
  },
  {
    time: "2025-09-15 10:55:47",
    amount: "14.20",
  },
  {
    time: "2025-08-13 21:43:52",
    amount: "2.38",
  },
  {
    time: "2025-08-07 17:47:57",
    amount: "0.50",
  },
  {
    time: "2025-07-15 01:42:30",
    amount: "13.13",
  },
  {
    time: "2025-06-09 14:58:36",
    amount: "2.31",
  },
  {
    time: "2025-06-03 19:06:50",
    amount: "18.22",
  },
]);

// 返回
const goBack = () => {
  uni.navigateBack();
};

// 全部激活
const activateAll = () => {
  activateCount.value = activatableAmount.value;
};

// 确认激活
const confirmActivate = () => {
  if (!activateCount.value) {
    uni.showToast({
      title: "请输入激活数量",
      icon: "none",
    });
    return;
  }

  if (parseFloat(activateCount.value) > parseFloat(activatableAmount.value)) {
    uni.showToast({
      title: "激活数量不能超过可激活金额",
      icon: "none",
    });
    return;
  }

  // TODO: 调用激活接口
  console.log("激活数量:", activateCount.value);
  uni.showToast({
    title: "激活成功",
    icon: "none",
  });

  // 清空输入
  activateCount.value = "";
};
</script>

<style lang="scss" scoped>
.page-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.content {
  padding: 32rpx;
  padding-top: 20rpx;
}

// 可激活抵用券卡片
.activate-card {
  background: linear-gradient(135deg, #ffd000 0%, #ff9500 100%);
  border-radius: 16rpx;
  padding: 40rpx 32rpx;
  margin-bottom: 24rpx;
  display: flex;
  align-items: center;
  gap: 24rpx;
}

.card-icon {
  width: 80rpx;
  height: 80rpx;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.card-label {
  font-size: 28rpx;
  color: #fff;
}

.card-amount {
  font-size: 48rpx;
  color: #fff;
  font-weight: 700;
}

// 激活表单
.activate-form {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 32rpx;
  margin-bottom: 24rpx;
}

.form-title {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  margin-bottom: 32rpx;
}

.form-item {
  margin-bottom: 32rpx;

  &:last-child {
    margin-bottom: 0;
  }
}

.form-label {
  font-size: 28rpx;
  color: #333;
  display: block;
  margin-bottom: 16rpx;
}

.input-wrapper {
  position: relative;

  :deep(.uni-easyinput__content-input) {
    font-size: 28rpx;
    height: 80rpx;
  }
}

.all-btn {
  position: absolute;
  right: 16rpx;
  top: 50%;
  transform: translateY(-50%);
  padding: 12rpx 24rpx;
  background-color: #ff9500;
  color: #fff;
  font-size: 24rpx;
  border-radius: 8rpx;

  &:active {
    opacity: 0.8;
  }
}

.balance-info {
  display: flex;
  align-items: center;
  padding: 24rpx;
  background-color: #f5f5f5;
  border-radius: 12rpx;
}

.balance-label {
  font-size: 28rpx;
  color: #666;
}

.balance-amount {
  font-size: 32rpx;
  color: #ff9500;
  font-weight: 600;
  margin-left: 16rpx;
}

.submit-btn {
  width: 100%;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background: linear-gradient(135deg, #ffd000 0%, #ff9500 100%);
  color: #fff;
  font-size: 32rpx;
  font-weight: 600;
  border-radius: 12rpx;
  margin-top: 48rpx;

  &:active {
    opacity: 0.8;
  }
}

// 激活记录
.record-section {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 32rpx;
}

.record-header {
  margin-bottom: 24rpx;
}

.record-title {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
}

.record-list {
  display: flex;
  flex-direction: column;
}

.record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 0;
  border-bottom: 1rpx solid #f5f5f5;

  &:last-child {
    border-bottom: none;
  }
}

.record-left {
  flex: 1;
}

.record-time {
  font-size: 28rpx;
  color: #333;
}

.record-right {
  margin-left: 32rpx;
}

.record-amount {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
}

// 空状态
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 120rpx 0;
}

.empty-image {
  width: 300rpx;
  height: 300rpx;
  margin-bottom: 32rpx;
  opacity: 0.3;
}

.empty-text {
  font-size: 28rpx;
  color: #999;
}
</style>
